$(function () {
  //隐藏遮罩层
  if ($("#screenbox").length > 0) {
    HideLoad();
  }

  //radio选择框操作
  $("input[type=radio]").click(function () {
    var name = $(this).attr('name');
    $("input[name=" + name).siblings("div").children("span").removeClass("active");
    $(this).siblings("div").children("span").addClass("active");
  });

  $('.mylaydate').each(function () {
    var option = eval('(' + $(this).attr('data-para') + ')');
    option.elem = this;
    LoadDateTime(option);
  })
})

function LoadDateTime(option) {
  if (option.maxcontrol != null && option.maxcontrol != undefined && $(option.maxcontrol) != undefined) {
    option.done = function (value, date, endDate) {
      if ($(option.maxcontrol).val() != '') {
        var enddate = $(option.maxcontrol).val();
        if (!CompareTime(value, enddate)) {
          ShowError('日期选择有误');
          $(option.elem).val('');
        }
      }
    }
  }
  if (option.mincontrol != null && option.mincontrol != undefined && $(option.mincontrol) != undefined) {
    option.done = function (value, date, endDate) {
      if ($(option.mincontrol).val() != '') {
        var startdate = $(option.mincontrol).val();
        if (!CompareTime(startdate, value)) {
          ShowError('日期选择有误');
          $(option.elem).val('');
        }
      }
    }
  }
  laydate.render(option);
}

//纯数字验证
function validateNum(str) {
  var reg = /^\d+$/;
  return reg.test(str);
}

//检查是否为整数
function validateIsInteger(str) {
  var reg = /^-?\d+$/;
  return reg.test(str);
}

//验证是否为空或者空字符串
function validateIsNullOrEmpty(str) {
  if (str == null || str == '')
    return true;
  return false;
}

//字符串长度验证
function validateLengthMin(str, len) {
  if (str.length < len) {
    return false;
  }
  return true;
}
function validateLengthMax(str, len) {
  if (str.length > len) {
    return false;
  }
  return true;
}

//特殊字符验证
function validateOther(str) {
  var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
  for (var i = 0; i < str.length; i++) {
    if (pattern.test(str.substr(i, 1))) {
      return false;
    }
  }
  return true;
}

// 验证时间
function validateDateTime(str, type) {
  var reg = /^(\d{4})[\-\/\s]?(0\d{1}|1[0-2])[\-\/\s]?(0\d{1}|[12]\d{1}|3[01])\s(0\d{1}|1\d{1}|2[0-3]):[0-5]\d{1}:([0-5]\d{1})$/;
  switch (type) {
    case 'date':
      reg = /^(\d{4})[\-\/\s]?(0\d{1}|1[0-2])[\-\/\s]?(0\d{1}|[12]\d{1}|3[01])$/;
      break;
    case 'time':
      reg = /^(0\d{1}|1\d{1}|2[0-3]):[0-5]\d{1}:([0-5]\d{1})$/;
      break;
  }
  return reg.test(str);
}

// 验证IP地址
function validateIp(str) {
  var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
  return reg.test(str);
}

// 验证手机号
function validatePhone(str) {
  var pattern = /^1[34578]\d{9}$/;
  return pattern.test(str);
}

//验证email
function validateEmail(str) {
  if (! /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test(str)) {
    return false;
  }
  return true;
}


//验证
function myvalidate(str, rules) {
  // 非空验证
  if (rules.notEmpty != null && typeof (rules.notEmpty) != 'undefined' && validateIsNullOrEmpty(str)) {
    ShowError(rules.message + '不能为空');
    return false;
  }
  // 长度验证 enabled true 可以为空 false 不能为空
  if (rules.stringLength != null && typeof (rules.stringLength) != 'undefined') {
    var needCheck = false;
    if (rules.stringLength.enabled != null && typeof (rules.stringLength.enabled) != 'undefined' && !rules.stringLength.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      if (rules.stringLength.min != null && typeof (rules.stringLength.min) != 'undefined' && !validateLengthMin(str, rules.stringLength.min)) {
        ShowError(rules.message + '最少' + rules.stringLength.min + '位');
        return false;
      }
      if (rules.stringLength.max != null && typeof (rules.stringLength.max) != 'undefined' && !validateLengthMax(str, rules.stringLength.max)) {
        ShowError(rules.message + '最多' + rules.stringLength.max + '位');
        return false;
      }
    }
  }
  // 正则表达式验证
  if (rules.regexp != null && typeof (rules.regexp) != 'undefined') {
    var needCheck = false;
    if (rules.regexp.enabled != null && typeof (rules.regexp.enabled) != 'undefined' && !rules.regexp.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      var pattern = rules.regexp.regexp;
      if (!pattern.test(str)) {
        ShowError(rules.message + '格式错误');
        return false;
      }
    }
  }
  // 整数验证
  if (rules.isInteger != null && typeof (rules.isInteger) != 'undefined') {
    var needCheck = false;
    if (rules.isInteger.enabled != null && typeof (rules.isInteger.enabled) != 'undefined' && !rules.isInteger.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      if (!validateIsInteger(str)) {
        ShowError(rules.message + '必须为整数');
        return false;
      }
      if (rules.isInteger.notIn != null && typeof (rules.isInteger.notIn) != 'undefined') {
        for (var i = 0; i < rules.isInteger.notIn.length; i++) {
          if (parseInt(str) == rules.isInteger.notIn[i]) {
            ShowError(rules.message + '值不能为' + rules.isInteger.notIn[i])
            return false;
          }
        }
      }
    }
  }
  // 时间验证
  if (rules.isDateTime != null && typeof (rules.isDateTime) != 'undefined') {
    var needCheck = false;
    if (rules.isDateTime.enabled != null && typeof (rules.isDateTime.enabled) != 'undefined' && !rules.isDateTime.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      if (!validateDateTime(str, rules.isDateTime.type)) {
        ShowError(rules.message + '格式不对');
        return false;
      }
      if (rules.isDateTime.min != null && typeof (rules.isDateTime.min) != 'undefined' && rules.isDateTime.min != '') {
        var min = new Date(rules.isDateTime.min.replace("-", "/").replace("-", "/"));
        var time = new Date(str.replace("-", "/").replace("-", "/"));
        if (time < min) {
          ShowError(rules.message + '结束时间小于开始时间');
          return false;
        }
      }
      if (rules.isDateTime.max != null && typeof (rules.isDateTime.max) != 'undefined' && rules.isDateTime.max != '') {
        var max = new Date(rules.isDateTime.max.replace("-", "/").replace("-", "/"));
        var time = new Date(str.replace("-", "/").replace("-", "/"));
        if (time > min) {
          ShowError(rules.message + '开始时间小于结束时间');
          return false;
        }
      }
    }
  }
  // IP验证
  if (rules.isIp != null && typeof (rules.isIp) != 'undefined') {
    if (rules.isIp.enabled != null && typeof (rules.isIp.enabled) != 'undefined' && !rules.isIp.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      if (!validateIp(str)) {
        ShowError(rules.message + '格式不正确')
        return false;
      }
    }
  }
  // 相等验证
  if (rules.equles != null && typeof (rules.equles) != 'undefined') {
    if (str != rules.equles.value) {
      ShowError(rules.equles.message);
      return false;
    }
  }
  // 手机号码验证
  if (rules.phone != null && typeof (rules.phone) != 'undefined') {
    var needCheck = false;
    if (rules.phone.enabled != null && typeof (rules.phone.enabled) != 'undefined' && !rules.phone.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      if (!validatePhone(str)) {
        ShowError(rules.message + '格式不正确');
        return false;
      }
    }
  }
  // Email验证
  if (rules.email != null && typeof (rules.email) != 'undefined') {
    var needCheck = false;
    if (rules.email.enabled != null && typeof (rules.email.enabled) != 'undefined' && !rules.email.enabled) {
      if (validateIsNullOrEmpty(str)) {
        ShowError(rules.message + '不能为空');
        return false;
      }
      needCheck = true;
    }
    else {
      if (!validateIsNullOrEmpty(str)) {
        needCheck = true;
      }
    }
    if (needCheck) {
      if (!validateEmail(str)) {
        ShowError(rules.message + '格式不正确');
        return false;
      }
    }
  }
  return true;
}
function validateBoth(fieldsRule) {
  for (var i = 0; i < fieldsRule.length; i++) {
    if (!myvalidate(fieldsRule[i].value, fieldsRule[i].rule)) {
      return false;
    }
  }
  return true;
}

//日期查询按钮点击操作
function TimeSearchBtnClick(type, start, end, formattype) {
  switch (type) {
    case 'today':
      {
        $(start).val(getToDayDate(formattype));
        $(end).val(getToDayDate(formattype));
      }
      break;
    case 'yesterday':
      {
        $(start).val(getYesterdayDate(formattype));
        $(end).val(getYesterdayDate(formattype));
      }
      break;
    case 'thisweek':
      {
        $(start).val(getWeekStartDate(formattype));
        $(end).val(getWeekEndDate(formattype));
      }
      break;
    case 'lastweek':
      {
        $(start).val(getLastWeekStartDate(formattype));
        $(end).val(getLastWeekEndDate(formattype));
      }
      break;
    case 'thismonth':
      {
        $(start).val(getMonthStartDate(formattype));
        $(end).val(getMonthEndDate(formattype));
      }
      break;
    case 'lastmonth':
      {
        $(start).val(getLastMonthStartDate(formattype));
        $(end).val(getLastMonthEndDate(formattype));
      }
      break;
  }
}

//去掉字符串里面的html标签
function delhtml(str) {
  return str.replace(/<.*?>/ig, "");
}

//html编码
function html2Escape(sHtml) {
  return sHtml.replace(/[<>&"]/g, function (c) { return { '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;' }[c]; });
}

//html解码
function escape2Html(str) {
  var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
  return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; });
}

//设置cookie
function setCookie(c_name, value) {
  var expiredays = 1;
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());

}

//读取cookies
function getCookie(name) {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if (arr = document.cookie.match(reg))
    return (arr[2]);
  else
    return null;
}

//计算两个时间相差的秒数
function GetDateDiff(startTime, endTime, diffType) {
  //将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式 
  startTime = startTime.toString().replace(/\-/g, "/");
  endTime = endTime.toString().replace(/\-/g, "/");
  //将计算间隔类性字符转换为小写
  diffType = diffType.toLowerCase();
  var sTime = new Date(startTime); //开始时间
  var eTime = new Date(endTime); //结束时间
  //作为除数的数字
  var timeType = 1;
  switch (diffType) {
    case "second":
      timeType = 1000;
      break;
    case "minute":
      timeType = 1000 * 60;
      break;
    case "hour":
      timeType = 1000 * 3600;
      break;
    case "day":
      timeType = 1000 * 3600 * 24;
      break;
    default:
      break;
  }
  return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(timeType));
}

//切指定长度
function cutstr(str, len) {
  return str.substring(0, len) + '...';
}

//从json对象中的某个字段变成数组
function GetArrayByJson(objList, fields) {
  var rearray = new Array();
  for (var i = 0; i < objList.length; i++) {
    rearray[i] = objList[i][fields];
  }
  return rearray;
}

//从json对象中返回符合条件的数组
function GetNewArrayByJson(list, condition) {
  var arr = [];
  for (var i = 0; i < list.length; i++) {
    var obj = list[i];
    if (eval('(' + condition + ')')) {
      arr.push(obj);
    }
  }
  return arr;
}

//加载下拉列表框
//rows 数据列表
//valueField value对应字段
//textField 显示文本对应字段
function LoadSelect(rows, valueField, textField) {
  var optionStr = '';
  for (var i = 0; i < rows.length; i++) {
    optionStr += '<option value="' + rows[i][valueField] + '">' + rows[i][textField] + '</option>';
  }
  return optionStr;
}

//加载选择框列表
//json数据列表 name input的id对应的字段
//value input 的 data-value对应的字段
//des 显示文字对应的字段
//n 每行展示多少个
function LoadCheckBoxList(json, name, value, des, n) {
  var re = '';
  for (var i = 0; i < json.length; i++) {
    re += '<div class="checkbox checkbox-success checkbox-inline">';
    re += '<input id="cb' + json[i][name] + '" type="checkbox" class="styled" data-value="' + json[i][value] + '" />';
    re += '<label for="cb' + json[i][name] + '">' + json[i][des] + '</label>';
    re += '</div >';
    if (n != 0 && (i + 1) % n == 0) {
      re += '<br />';
    }
  }
  return re;
}

//选择所有
function SelectAll(flag) {
  var m_list_checkbox = $("input[name='cid']");
  for (var i = m_list_checkbox.length - 1; i >= 0; i--) {
    m_list_checkbox[i].checked = flag;
  }
}

//批量控制操作
function CheckCID() {
  var checkok = false;
  var e = $("input[name='cid']");
  for (var i = 0; i < e.length; i++) {
    if (e[i].type == "checkbox") {
      if (e[i].checked == true) {
        checkok = true;
        break;
      }
    }
  }
  if (checkok)
    return confirm('确认要操作选中记录吗？');
  else {
    ShowError("请选择要操作的记录!", 3, '');
    return false;
  }
}

//获取所有选中的ID
function GetAllCheckCID() {
  var allcid = '';
  var e = $("input[name='cid']");
  for (var i = 0; i < e.length; i++) {
    if (e[i].type == "checkbox") {
      if (e[i].checked == true) {
        allcid += e[i].value + ',';
      }
    }
  }
  return allcid.substring(0, allcid.length - 1);
}

//显示详细表格
function ShowDetail(obj) {
  var id = "record" + obj.id;
  if ($('#' + id).is(":hidden")) {
    $('#' + id).show();
    obj.src = "/Content/images/up.gif"
  }
  else {
    $('#' + id).hide();
    obj.src = "/Content/images/down.gif"
  }
}

//加载表格
function LoadTable(fields, rows, condition) {
  var reHtml = '<thead><tr>';
  for (var i = 0; i < fields.length; i++) {
    reHtml += '<th>' + fields[i].name + '</th>';
  }
  reHtml += '</tr></thead><tbody>';

  for (var i = 0; i < rows.length; i++) {
    var obj = rows[i];
    if (eval('(' + condition + ')')) {
      reHtml += '<tr>';
      for (var j = 0; j < fields.length; j++) {
        if (fields[j].formatter != null)
          reHtml += '<td>' + fields[j].formatter(obj) + '</td>';
        else
          reHtml += '<td>' + obj[fields[j].field] + '</td>';
      }
      reHtml += '</tr>';
    }
  }
  reHtml += '</tbody>'
  return reHtml;
}

//ajax请求
function MyAjax(url, jsonText, callback) {
  //ShowLoad();
  $.ajax({
    type: "POST",
    url: url,
    data: jsonText,
    contentType: "application/json;charset=utf-8",
    dataType: "json",
    async: true,//异步     
    success: function (json) {
      callback(json);
    }, error: function () {
      console.log('网络错误【' + url + '】！');
      HideLoad();
    }
  })
}

//通用回调
function MyCallBack(json) {
  if (json.s == 0) {
    ShowSuccess(json.m, 0.5, json.u);
    HideLoad();
  }
  else {
    ShowError(json.m, 2, json.u);
    HideLoad();
  }
}

//获取get参数
function GetQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return decodeURI(unescape(r[2])); return null;
}

//显示错误信息
function ShowError(msg, time = 2, url = '') {
  HideMessage();
  $("#myError").text(msg);
  $("#myError").show();
  setTimeout(function () {
    $("#myError").hide();
    if (url != '') {
      var urlNow = location.href;
      location.href = url + '?resultUrl=' + urlNow;
    }
  }, time * 1000);
}

//显示成功信息
function ShowSuccess(msg, time, url) {
  HideMessage();
  $("#mySuccess").text(msg);
  $("#mySuccess").show();
  setTimeout(function () {
    $("#mySuccess").hide();
    if (url != '') {
      location.href = url;
    }
  }, time * 1000);
}

//隐藏消息
function HideMessage() {
  $("#myError").hide();
  $("#mySuccess").hide();
}

//显示隐藏遮罩层
function ShowLoad() {
  $("#screenbox").show();
}
function HideLoad() {
  $("#screenbox").hide();
}

//在新窗口中打开链接
function OpenInNewWindow(url, name, width, height) {
  var left = (window.screen.availWidth - width) / 2;
  var top = (window.screen.availHeight - height) / 2;
  var openthiswin = window.open(url, name, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
  if (openthiswin != null) openthiswin.focus();
}

//创建打开新窗口的链接
function CreateOpenNewWindowHref(name, url, winname, width, height) {
  return '<a href="javascript:void(0);" onclick="OpenInNewWindow(\'' + url + '\',\'' + winname + '\',' + width + ',' + height + ')">' + name + '</a>';
}

//菜单
var pagelist = [{
  "PageID": 1,
  "ParentID": 0,
  "Title": "个人信息",
  "Link": "/Home/Index",
  "Description": "glyphicon-user"
}, {
  "PageID": 2,
  "ParentID": 0,
  "Title": "保险柜服务",
  "Link": "/Home/TransferScore",
  "Description": "glyphicon-shopping-cart"
}, {
  "PageID": 3,
  "ParentID": 0,
  "Title": "流水记录",
  "Link": "",
  "Description": "glyphicon-list-alt"
}, {
  "PageID": 4,
  "ParentID": 0,
  "Title": "流水报表",
  "Link": "",
  "Description": "glyphicon-book"
}, {
  "PageID": 31,
  "ParentID": 3,
  "Title": "转出记录",
  "Link": "/Record/TranRecord",
  "Description": ""
}, {
  "PageID": 32,
  "ParentID": 3,
  "Title": "接收记录",
  "Link": "/Record/TransInRecord",
  "Description": ""
}, {
  "PageID": 33,
  "ParentID": 3,
  "Title": "返利记录",
  "Link": "/Record/RebateRecord",
  "Description": ""
}, {
  "PageID": 41,
  "ParentID": 4,
  "Title": "日统计",
  "Link": "/Total/TotalDay",
  "Description": ""
}/*, {
  "PageID": 42,
  "ParentID": 4,
  "Title": "周统计",
  "Link": "/Total/TotalWeek",
  "Description": ""
}*/, {
  "PageID": 43,
  "ParentID": 4,
  "Title": "月统计",
  "Link": "/Total/TotalMonth",
  "Description": ""
}/*, {
  "PageID": 5,
  "ParentID": 0,
  "Title": "进出货业务",
  "Link": "",
  "Description": "glyphicon-usd"
}, {
  "PageID": 51,
  "ParentID": 5,
  "Title": "进货业务",
  "Link": "/BuySell/Buy",
  "Description": ""
}, {
  "PageID": 52,
  "ParentID": 5,
  "Title": "出货业务",
  "Link": "/BuySell/Sell",
  "Description": ""
}, {
  "PageID": 53,
  "ParentID": 5,
  "Title": "业务流水",
  "Link": "/BuySell/BuyRecord",
  "Description": ""
}, {
  "PageID": 6,
  "ParentID": 0,
  "Title": "失效时间设置",
  "Link": "/Home/LoginOutTime",
  "Description": "glyphicon glyphicon-dashboard"
}*/];

//快捷金币选择
var transcorelist = [
  {
    "name": "20万",
    "value": "200000"
  }, {
    "name": "60万",
    "value": "600000"
  }, {
    "name": "100万",
    "value": "1000000"
  }, {
    "name": "200万",
    "value": "2000000"
  }, {
    "name": "1000万",
    "value": "10000000"
  }
];

//进货快速金币选择
var buyscorelist = [{ "name": "1", "value": "1" }, { "name": "2", "value": "2" }, { "name": "5", "value": "5" }, { "name": "10", "value": "10" }, { "name": "20", "value": "20" }];
//出货快速金币选择
var sellscorelist = [{ "name": "1", "value": "1" }, { "name": "2", "value": "2" }, { "name": "5", "value": "5" }, { "name": "10", "value": "10" }, { "name": "20", "value": "20" }];

//数字改成大写汉字
function convertCurrency(money, end) {
  // 汉字的数字
  var cnNums = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
  // 基本单位
  var cnIntRadice = new Array('', '十', '百', '千');
  // 对应整数部分扩展单位
  var cnIntUnits = new Array('', '万', '亿', '兆');
  // 对应小数部分单位
  var cnDecUnits = new Array('角', '分', '毫', '厘');
  // 整数金额时后面跟的字符
  var cnInteger = '';
  // 整型完以后的单位
  var cnIntLast = end;
  // 最大处理的数字
  var maxNum = 999999999999999.9999;
  // 金额整数部分
  var integerNum;
  // 金额小数部分
  var decimalNum;
  // 输出的中文金额字符串
  var chineseStr = '';
  // 分离金额后用的数组，预定义
  var parts;
  if (money == '') {
    return '';
  }
  money = parseFloat(money);
  if (money >= maxNum) {
    // 超出最大处理数字
    return '超出最大处理数字';
  }
  if (money == 0) {
    chineseStr = cnNums[0] + cnIntLast + cnInteger;
    return chineseStr;
  }
  // 转换为字符串
  money = money.toString();
  if (money.indexOf('.') == -1) {
    integerNum = money;
    decimalNum = '';
  } else {
    parts = money.split('.');
    integerNum = parts[0];
    decimalNum = parts[1].substr(0, 4);
  }
  // 获取整型部分转换
  if (parseInt(integerNum, 10) > 0) {
    var zeroCount = 0;
    var IntLen = integerNum.length;
    for (var i = 0; i < IntLen; i++) {
      var n = integerNum.substr(i, 1);
      var p = IntLen - i - 1;
      var q = p / 4;
      var m = p % 4;
      if (n == '0') {
        zeroCount++;
      } else {
        if (zeroCount > 0) {
          chineseStr += cnNums[0];
        }
        // 归零
        zeroCount = 0;
        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
      }
      if (m == 0 && zeroCount < 4) {
        chineseStr += cnIntUnits[q];
      }
    }
    chineseStr += cnIntLast;
  }
  // 小数部分
  if (decimalNum != '') {
    var decLen = decimalNum.length;
    for (var i = 0; i < decLen; i++) {
      var n = decimalNum.substr(i, 1);
      if (n != '0') {
        chineseStr += cnNums[Number(n)] + cnDecUnits[i];
      }
    }
  }
  if (chineseStr == '') {
    chineseStr += cnNums[0] + cnIntLast + cnInteger;
  } else if (decimalNum == '') {
    chineseStr += cnInteger;
  }
  return chineseStr;
}

//将数值四舍五入(保留2位小数)后格式化成金额形式 
function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g, '');
  if (isNaN(num))
    num = "0";
  sign = (num == (num = Math.abs(num)));
  //num = Math.floor(num * 100 + 0.50000000001);
  //cents = num % 100;
  //num = Math.floor(num / 100).toString();
  //if (cents < 10)
  //  cents = "0" + cents;
  num = num.toString();
  for (var i = 0; i < Math.floor((num.length - (1 + i)) / 4); i++)
    num = num.substring(0, num.length - (5 * i + 4)) + ',' +
      num.substring(num.length - (5 * i + 4));
  return (((sign) ? '' : '-') + num + " "/* + '.' + cents*/);
}